﻿
@{
    ViewBag.Title = "修改商户";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@using Mate.Framework.Extensions
@model Mate.Dto.Merchant.MerchantModel
@section styles{
    <link href="~/bootstrap/plugins/jquery-file-upload/css/jquery.fileupload.css" rel="stylesheet" />
}

@section scripts{
    <script src="~/bootstrap/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
    <script src="~/bootstrap/plugins/jquery-validation/dist/additional-methods.min.js"></script>
    <script src="~/bootstrap/scripts/custom/form-validation.js" charset="gbk"></script>

    <script src="~/bootstrap/plugins/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script>
    <script src="~/bootstrap/plugins/jquery-file-upload/js/jquery.fileupload.js"></script>
    <script src="~/bootstrap/scripts/custom/form-fileupload.js"></script>

    <script src="~/js/admin.js?v=1.0"></script>
    <script language="javascript" type="text/javascript">
        $(function () {
            var rules = {
                merchantname: {
                    required: true
                },
                lat: {
                    number:true
                },
                lng: {
                    number: true
                },
                percost: {
                    number: true
                }

            };
            FormValidation.BasicValidation(rules);

            $("input[name='cb_opendays']").click(function () {
                var cbIds = [];
                $("input[name='cb_opendays']:checked").each(function () {
                    cbIds.push($(this).val());
                });
                $("#opendays").val(cbIds.toString());
            });
            $("input[name='cb_opendays']").eq(0).click().click();

            $("input[name='cb_merchanttag']").click(function () {
                var cbIds = [];
                $("input[name='cb_merchanttag']:checked").each(function () {
                    cbIds.push($(this).val());
                });
                $("#merchanttag").val(cbIds.toString());
            });
            $("input[name='cb_opendays']").eq(0).click().click();

        });
         @Html.UploadPictureJs("merchantlogo");
    </script>
}

<ul class="page-breadcrumb breadcrumb">
    <li>
        <a href="@Url.Action("Index","Merchant")">
            商户管理
        </a>
        <i class="fa fa-angle-right"></i>
    </li>
    <li>
        修改商户
    </li>
</ul>

<div class="row">
    <div class="col-md-12">
        <div class="portlet-body form">
            <!-- BEGIN FORM-->
            @using (Html.BeginForm("Edit", "Merchant", FormMethod.Post, new { @class = "form-horizontal", @id = "form_ff_validation", @novalidate = "novalidate" }))
            {
            <div class="form-body">
                @Html.TextFor("名称", "merchantname", value: Model.merchantname)
                <div class="form-group">
                    <label class="control-label col-xs-3">
                        商户类型
                        <span class="required">*</span>
                    </label>
                    <div class="col-xs-4">
                        <select id="merchantcategory" name="merchantcategory" class="form-control">
                            @if (Model.MerchantCategorieList != null)
                            {
                                var parentList = Model.MerchantCategorieList.Where(x => x.parentid == 0).ToList();
                                foreach (var item in parentList)
                                {
                                    <option value="@(item.id)" @(item.id == Model.merchantcategory ? "selected='selected'" : "")>@item.merchantcategoryname</option>
                                    if (item.children.Any())
                                    {
                                        foreach (var item2 in item.children)
                                        {
                                            <option value="@(item2.id)" @(item2.id == Model.merchantcategory ? "selected='selected'" : "")>├── @item2.merchantcategoryname</option>
                                            if (item2.children.Any())
                                            {
                                                foreach (var item3 in item2.children)
                                                {
                                                    <option value="@(item3.id)" @(item3.id == Model.merchantcategory ? "selected='selected'" : "")>├──── @item3.merchantcategoryname</option>
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-xs-3">
                        商户地区
                        <span class="required">*</span>
                    </label>
                    <div class="col-xs-4">
                        <select id="merchantdistrict" name="merchantdistrict" class="form-control">
                            @if (Model.DistrictList != null)
                            {
                                var parentList = Model.DistrictList.Where(x => x.parentid == 0).ToList();
                                foreach (var item in parentList)
                                {
                                    <option value="@(item.id)" @(item.id == Model.merchantdistrict ? "selected='selected'" : "")>@item.districtname</option>
                                    if (item.children.Any())
                                    {
                                        foreach (var item2 in item.children)
                                        {
                                            <option value="@(item2.id)" @(item2.id == Model.merchantdistrict ? "selected='selected'" : "")>├── @item2.districtname</option>
                                            if (item2.children.Any())
                                            {
                                                foreach (var item3 in item2.children)
                                                {
                                                    <option value="@(item3.id)" @(item3.id == Model.merchantdistrict ? "selected='selected'" : "")>├──── @item3.districtname</option>
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                @Html.TextFor("商户详细地址", "merchantaddress", value: Model.merchantaddress)

                @Html.UploadPictureFor("商户图片", "merchantlogo", picSrc: Model.merchantlogo)
                @Html.TextFor("纬度", "lat", value: (Model.lat == null ? "" : Model.lat.ToString()))
                @Html.TextFor("经度", "lng", value: (Model.lng == null ? "" : Model.lng.ToString()))
                @Html.TextFor("人均消费", "percost", value: (Model.percost == null ? "" : Model.percost.ToString()))
                @Html.TextFor("电话号码", "phone", value: Model.phone)
                @Html.CheckboxFor("营业时间", "cb_opendays", new List<KeyValuePair<string, string>>()
                                                {
                                                    new KeyValuePair<string, string>("0","星期天"),
                                                    new KeyValuePair<string, string>("1","星期一"),
                                                    new KeyValuePair<string, string>("2","星期二"),
                                                    new KeyValuePair<string, string>("3","星期三"),
                                                    new KeyValuePair<string, string>("4","星期四"),
                                                    new KeyValuePair<string, string>("5","星期五"),
                                                    new KeyValuePair<string, string>("6","星期六")
                                                },selectValue:(!string.IsNullOrWhiteSpace(Model.opendays)?Model.opendays.Split(','):null)
                                                ,inputWidth:8)
                <input type="hidden" id="opendays" name="opendays" />

                @Html.CheckboxFor("商户标签", "cb_merchanttag", Model.MerchantTagList,selectValue:(!string.IsNullOrWhiteSpace(Model.merchanttag) ?Model.merchanttag.Split(','):null)
                                               ,inputWidth:8)
                <input type="hidden" id="merchanttag" name="merchanttag" />

                @Html.RadioFor("是否品牌", "is_brand", new List<KeyValuePair<string, string>>()
                                                {
                                                    new KeyValuePair<string, string>("1","是"),
                                                    new KeyValuePair<string, string>("0","否")
                                                },selectValue:Model.is_brand.ToString())
                <div class="form-group">
                    <label class="control-label col-sm-3">
                        品牌名称
                        <span class="required">*</span>
                    </label>
                    <div class="col-sm-4">
                        @Html.TextBoxFor(x => x.brand_name, new { @class = "form-control" })
                    </div>
                </div>



                @Html.RadioFor("是否热门", "is_hot", new List<KeyValuePair<string, string>>()
                                              {
                                                  new KeyValuePair<string, string>("1","是"),
                                                  new KeyValuePair<string, string>("0","否")
                                              },selectValue:Model.is_hot?.ToString())
                @Html.RadioFor("状态", "is_open", new List<KeyValuePair<string, string>>()
                                                {
                                                    new KeyValuePair<string, string>("1","营业"),
                                                    new KeyValuePair<string, string>("2","未营业")
                                                },selectValue:Model.is_open.ToString())
            </div>
                <div class="form-actions fluid">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn green" type="button" onclick="admin.AddSubmit('@Url.Action("Index")')"> 提交 <i class="fa fa-check"></i> </button>
                        <a class="btn default" role="button" href="@Url.Action("Index")"> 返回 <i class="fa fa-reply"></i></a>
                    </div>
                </div>
            }
            <!-- END FORM-->
        </div>
    </div>
    <!-- END VALIDATION STATES-->
</div>
